<jsp:useBean id="utilisateur" class="fr.p10.miage.gestionabsence.model.Utilisateur" scope="session"/>
<%@page import="fr.p10.miage.gestionnote.model.Controle"%>
<%@page import="java.util.List"%>
<%@page import="fr.p10.miage.gestionnote.model.EcIntervenant"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!doctype html>
<html lang="fr" >
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="">
        <title>Accueil</title>
        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/font-awesome.css" rel="stylesheet">
        <link href="css/index-bo.css" rel="stylesheet">
    </head>

    <body class="skin-black fixed">
        
        <%@include file="../../../header.jsp" %>
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <%@include file="../../../asideLeft.jsp" %>
            <aside class="right-side">
                <%
                    EcIntervenant ecIntervenant = (EcIntervenant) request.getAttribute("ecIntervenant");
                %>
                <section class="content-header">
                    <h1><% out.println(ecIntervenant.getNom()); %> <% out.println(ecIntervenant.getAnneePromotion());%></h1>
                    <html:link action="/ec-intervenant" linkName="Liste ec">
                    <button type="button" class="btn btn-default pull-right" style="background-color: #eee; margin-bottom: 15px;" ><span class="glyphicon glyphicon-chevron-left" ></span> Retour</button>
                        <html:param name="idec">
                            <% out.print(ecIntervenant.getIdec()); %>
                        </html:param>
                    </html:link>
                </section>
                <section class="content">
                    <legend>Liste des contrôles</legend>
                    <div class="col-sm-offset-2 col-sm-8">
                        <html:messages property="succesInsertControle" id="succesInsertControle" message="true">
                                    <div class="alert alert-success">
                                        <span class="glyphicon glyphicon-info-sign"></span>      
                                        <bean:write  name="succesInsertControle"/>
                                    </div>
                        </html:messages>
                        <html:messages property="succesInsertPublierControle" id="succesInsertPublierControle" message="true">
                                    <div class="alert alert-success">
                                        <span class="glyphicon glyphicon-info-sign"></span>      
                                        <bean:write name="succesInsertPublierControle"/>
                                    </div>
                        </html:messages>
                        <html:messages property="succesInsertCommentaire" id="succesInsertCommentaire" message="true">
                                    <div class="alert alert-success">
                                        <span class="glyphicon glyphicon-info-sign"></span>      
                                        <bean:write name="succesInsertCommentaire"/>
                                    </div>
                        </html:messages>
                        <html:messages property="succesInsertPublierEc" id="succesInsertPublierEc" message="true">
                                    <div class="alert alert-success">
                                        <span class="glyphicon glyphicon-info-sign"></span>      
                                        <bean:write name="succesInsertPublierEc"/>
                                    </div>
                        </html:messages>                        
                        <html:messages property="succesModifControle" id="succesModifControle" message="true">
                                    <div class="alert alert-success">
                                        <span class="glyphicon glyphicon-info-sign"></span>      
                                        <bean:write name="succesModifControle"/>
                                    </div>
                        </html:messages>                            
                        <html:errors property="publier"/>
                    </div>    
                    
                    
                    <table class="table table-striped table-bordered">
                       <tr>
					<th>Libelle contrôle</th>
                                        <th>Type</th>
					<th>coef</th>
					<th>Echelle</th>
					<th>Publier</th>
					<th>Moyenne</th>
					<th>Note haute</th>
					<th>Note basse</th>
					<th>Nb noté</th>
					<th>Nb dispensé</th>
					<th>Reste</th>
					<th>Publier</th>
				</tr>
                                 <%
                                    if (ecIntervenant != null) {
                                    List<Controle> listeControles = ecIntervenant.getControles();
                                    for (int i = 0; i < listeControles.size(); i++) 
                                    {
                                    %>
				<tr>
					<td>
                                            <html:link action="/ec-consulter-controle" linkName="Consulter contrôle">
                                                <button class="btn btn-link" ><%out.println(listeControles.get(i).getLabel());%></button>
                                                <html:param name="idec">
                                                      <%out.print(ecIntervenant.getIdec());%>
                                                </html:param>
                                                <html:param name="idcontrole">
                                                      <%out.print(listeControles.get(i).getIdcontrole());%>
                                                </html:param>
                                                <html:param name="idp">
                                                      <%out.print(listeControles.get(i).getIdP());%>
                                                </html:param>
                                            </html:link>
                                        </td>
                                        <td><%out.println(listeControles.get(i).getTypeControleLabel(listeControles.get(i).getType()));%></td>
					<td><%out.println(listeControles.get(i).getCoefficient());%></td>
					<td><%out.println(listeControles.get(i).getEchelle());%></td>
					<td><% boolean isPublier=listeControles.get(i).isPublier();
                                        if(isPublier)out.println("Oui");
                                        else out.println("Non");
                                        %></td>
					<td><%out.println(listeControles.get(i).calculNoteMoyenneControle());%></td>
					<td><%out.println(listeControles.get(i).calculNoteHauteControle());%></td>
					<td><%out.println(listeControles.get(i).calculNoteBasseControle());%></td>
					<td><% int nbEtudiantNote=listeControles.get(i).calculNbEtudiantNote();
                                        out.println(nbEtudiantNote);%></td>
					<td><% int nbEtudiantDispense=listeControles.get(i).calculNbEtudiantDispense();
                                        out.println(nbEtudiantDispense);%></td>
					<td><% int nbEtudiantTot=ecIntervenant.getEtudiants().size();/*listeControles.get(i).calculNbEtudiantClasse();*/
                                        int nbEtudiantRestant=nbEtudiantTot-(nbEtudiantDispense+nbEtudiantNote);
                                        //if(nbEtudiantRestant==0) nbEtudiantRestant = nbEtudiantTot;
                                        out.println(nbEtudiantRestant+" / "+nbEtudiantTot);%></td>
		<% if(isPublier){ %>
                                        <td class="text-center"><button class="btn btn-default disabled">Notes publiées</button></td>
		<% }else{ %>
                                        <td class="text-center">
                                            <button class="btn btn-default" 
                                                    onclick="window.location='ec-publier-note.do?idec=<%= ecIntervenant.getIdec() %>&idControle=<%= listeControles.get(i).getIdcontrole()%>&idp=<%= listeControles.get(i).getIdP()%>'">
                                                Publier les notes
                                            </button>
                                        </td>
                <% } %>
                                </tr>
                                <%
                                    }
                                    }
                                 %>
                    </table>
                    <div class="row" style="margin-top: 30px; margin-bottom: 15px;">
                        <div class="col-md-4 text-center">
                            <html:link action="ec-redirect-formulaire-controle" linkName="Ajouter un contrôle">
                                <button class="btn btn-info" >Ajouter un contrôle</button>
                                <html:param name="idec">
                                      <%out.print(ecIntervenant.getIdec());%>
                                </html:param>
                                <html:param name="idp">
                                      <%out.print(ecIntervenant.getIdP());%>
                                </html:param>
                            </html:link>
                        </div>
                        <div class="col-md-4 text-center">
                            <html:link action="/ec-consulter-classe" linkName="Consulter la classe">
                                <button class="btn btn-info" >Consulter classe</button>
                                <html:param name="idec">
                                      <%out.print(ecIntervenant.getIdec());%>
                                </html:param>
                                <html:param name="idp">
                                      <%out.print(ecIntervenant.getIdP());%>
                                </html:param>
                            </html:link>
                        </div>
                        <div class="col-md-4 text-center">
                            
                        <% if(ecIntervenant.isPublier()){ %>
                         <button class="btn btn-default disabled" data-html="true" data-placement="bottom">
                             Moyenne final de l'EC Publiées
                         </button>     
                        <% }else{ %>
                         <button class="btn btn-info" 
                                 data-html="true" 
                                 data-placement="bottom"
                                 onclick="window.location='ec-publier-ec.do?idec=<%= ecIntervenant.getIdec()%>&idp=<%= ecIntervenant.getIdP()%>&idf=<%= ecIntervenant.getIdF()%>'">
                             Publier la moyenne finale et clore l'EC
                         </button>     
                        <% } %>
                        </div>
                    </div>
                </section>
            </aside>
        </div>
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
        <script src="js/bootstrap.js"/></script>
        <script src="js/app.js"/></script>
    </body>
</html>
